package com.chen.service;

import com.chen.dao.ProjectMapper;
import com.chen.entity.Project;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class ProjectService {

    @Autowired
    private ProjectMapper projectMapper;


    public boolean insertProject(Project project) {
        int insert = this.projectMapper.insertSelective(project);
        return insert > 0;
    }


    //用于初始化 主页查询的 下拉框 中的 项目数据
    public List<HashMap> queryProject(String uid) {
        return this.projectMapper.queryProject(uid);
    }


    public int queryProjectNumByPname(String pname){
       return this.projectMapper.queryProjectNumByPname(pname);
    }

    public  List<HashMap> queryProjectAndFansNum(String uid){
        return this.projectMapper.queryProjectAndFansNum(uid);
    }


    public Project queryProjectByPid(String pid){
        return  this.projectMapper.selectByPrimaryKey(new Project().setId(pid));
    }

    public boolean updateProject(Project project){
        int i = this.projectMapper.updateByPrimaryKeySelective(project);
        return i>0;
    }

    public boolean deleteProject(Project project){
        int i = this.projectMapper.deleteByPrimaryKey(project);
        return i>0;
    }
}
